﻿using System;
using System.Drawing;
using ConfExpert.Utility;
using DevExpress.Utils;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraEditors;
using Tailord;

namespace Tailord
{
   
    public partial class Options : XPopupForm
    {
        public Options()
        {
            InitializeComponent();
        }

        private void Settings_Load(object sender, EventArgs e)
        {
            nb.PaintStyleName = "SkinNavigationPane";
            tcSettingPages.ShowTabHeader = DefaultBoolean.False;

            btnKaydet.Click += new EventHandler(btnKaydet_Click);
            btnIptal.Click += new EventHandler(btnIptal_Click);

            cmbPopupFilterMode.Properties.Items.AddRange(System.Enum.GetValues(typeof(PopupFilterMode)));          
            cmbEditorShowMode.Properties.Items.AddRange(System.Enum.GetValues(typeof(EditorShowMode)));

            //cmbPopupFilterMode.EditValue = AppSession.Settings.PopupFilterMode;
            //cmbEditorShowMode.EditValue = AppSession.Settings.EditorShowMode;
            //chkEnableEvenRow.Checked = AppSession.Settings.EnableAppearanceEvenRow;
            //chkAllowFormGlass.Checked = AppSession.Settings.AllowFormGlass == DevExpress.Utils.DefaultBoolean.True;
            //colorPickEditZorunlu.EditValue = AppSession.Settings.ZorunluAlanRengi;

            chkEnableBarkod.Checked = Tailord.Properties.Settings.Default.BarcodeEnabled;
            cmbPort.Text = Tailord.Properties.Settings.Default.BarcodeComPort;
            cmbPort.Visible = chkEnableBarkod.Checked;

            //SkinHelper.InitSkinPopupMenu(SkinPopup);
            SkinHelper.InitSkinGallery(rgbiSkins, true, false);

            btnAktifYap.Click += new EventHandler(btnAktifYap_Click);
            btnAktifTemizle.Click += new EventHandler(btnAktifTemizle_Click);
            chkEnableBarkod.CheckedChanged += chkEnableBarkod_CheckedChanged;
        }

        void chkEnableBarkod_CheckedChanged(object sender, EventArgs e)
        {
            cmbPort.Visible = chkEnableBarkod.Checked;
        }

        void btnAktifTemizle_Click(object sender, EventArgs e)
        {
            //StartupForm = null;
            //StartupRibbonPage = null;
            //btnKaydet.PerformClick();

            Tailord.Properties.Settings.Default.BarcodeEnabled = chkEnableBarkod.Checked;
            Tailord.Properties.Settings.Default.BarcodeComPort = cmbPort.SelectedText;
            Tailord.Properties.Settings.Default.Save();

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        void btnAktifYap_Click(object sender, EventArgs e)
        {
            string MRUform = string.Empty;
            if (AppSession.MainForm.ActiveMdiChild != null)
            {
                XForm activeChild = AppSession.MainForm.ActiveMdiChild as XForm;
                MRUform = activeChild.ToString().Split(',')[0];
            }

            StartupForm = MRUform;
            StartupRibbonPage = AppSession.MainForm.Ribbon.SelectedPage.Text;
            btnKaydet.PerformClick();
        }


        void btnIptal_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        string StartupForm = null, StartupRibbonPage = null;
        void btnKaydet_Click(object sender, EventArgs e)
        {

            PopupFilterMode filterMode = (PopupFilterMode)Enum.Parse(typeof(PopupFilterMode), cmbPopupFilterMode.EditValue.ToString());
            AppSession.Settings.PopupFilterMode = filterMode;

            EditorShowMode showMode = (EditorShowMode)Enum.Parse(typeof(EditorShowMode), cmbEditorShowMode.EditValue.ToString());
            AppSession.Settings.EditorShowMode = showMode;

            AppSession.Settings.StartupForm = StartupForm;
            AppSession.Settings.StartupRibbonPage = StartupRibbonPage;

            AppSession.Settings.EnableAppearanceEvenRow = chkEnableEvenRow.Checked;
            //AppSession.Settings.GateIP = teGateIP.Text;
            //AppSession.Settings.SayimIP = teSayimIP.Text;
            //AppSession.Settings.WriterIP = teWriterIP.Text;

            if (colorEditKst.EditValue == null)
                colorEditKst.EditValue = Color.Black;

            AppSession.Settings.ZorunluAlanRengi = ((Color)colorPickEditZorunlu.EditValue).Name;
            AppSession.Settings.SkinName = DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName;
            AppSession.Settings.AllowFormGlass = chkAllowFormGlass.Checked ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False;

            //AppSession.Settings.Save();

            Tailord.Properties.Settings.Default.BarcodeEnabled = chkEnableBarkod.Checked;
            Tailord.Properties.Settings.Default.BarcodeComPort = cmbPort.SelectedText;
            Tailord.Properties.Settings.Default.Save();

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

       

        private void nbSettings_ActiveGroupChanged(object sender, DevExpress.XtraNavBar.NavBarGroupEventArgs e)
        {
            switch(nb.ActiveGroup.Name)
            {
                case "miUI": tcSettingPages.SelectedTabPage = tpUI; break;
                case "miTema": tcSettingPages.SelectedTabPage = tpTema; break;
                case "miGeneral": tcSettingPages.SelectedTabPage = tpGeneral; break;
            }
        }

  
    }
}